package com.bnq.logc.work

import android.content.Context
import com.bnq.logc.config.LogcConfig

object ScheduledUploadManager {

    fun getScheduledUpload(context: Context,config: LogcConfig.UploadScheduleConfig):IScheduledUpload{
        cancelWorkManagerIfThreadScheduled(context,config.strategy)
        return if(config.strategy == LogcConfig.UploadScheduleConfig.UploadStrategy.WorkManager)
            WorkManagerScheduledUpload(context)
        else ThreadPoolScheduledUpload()
    }

    fun cancelWorkManagerIfThreadScheduled(context: Context,strategy:LogcConfig.UploadScheduleConfig.UploadStrategy){
        if(strategy == LogcConfig.UploadScheduleConfig.UploadStrategy.ThreadScheduled){
            if(LogcUploadManager.getInstance(context).hasWorks()){
                LogcUploadManager.getInstance(context).cancel()
            }
        }
    }

}